package com.fake.path.adapter;

import java.util.ArrayList;

import com.fakepath.items.ItemPath;
import com.fakepath.views.OnResetAdapterListener;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class BaseClockAdapter extends ArrayAdapter<ItemPath> {
	private OnResetAdapterListener listener;
	private LayoutInflater inflate;

	public BaseClockAdapter(Context context, OnResetAdapterListener listener,
			ArrayList<ItemPath> objects) {
		super(context, -1, objects);
		this.listener = listener;
		this.inflate = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public void notifyDataSetChanged() {
		super.notifyDataSetChanged();
		listener.onNotifiDataSetChange();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (null == convertView) {
			convertView = inflate.inflate(android.R.layout.simple_list_item_1,
					null);
			holder = new ViewHolder();
			holder.textView = (TextView) convertView
					.findViewById(android.R.id.text1);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.textView.setTextColor(Color.BLACK);
		holder.textView.setText(getItem(position).getTitle());
		return convertView;
	}

	@Override
	public void notifyDataSetInvalidated() {
		super.notifyDataSetInvalidated();
		listener.onNotifiDataSetChange();
	}

	private class ViewHolder {
		TextView textView;
	}
}
